# Replication Code for "Interstate Rivalry, Major Power Status, and State
# Support for Arms Control", by Tobias Risse, published in International
# Interactions. All analyses run using R version 4.5.0. Regression results can
# be found in Online Appendix F, Tables A1 to A21.

rm(list=ls())

library(fixest)
library(lme4)
library(lmerTest)
library(openxlsx)
library(ordinal)
library(tidyverse)

load("data_mprivals.RData")

####### Main Effect ############################################################

# No Controls ------------------------------------------------------------------

model_nointbiv <- lm(armscontrolsupport ~ mprival, data = data)
summary(model_nointbiv)
save(model_nointbiv, file = "model_nointbiv.RData")

# Full Model -------------------------------------------------------------------

model_nointmain <- lmer(armscontrolsupport ~ mprival + mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer 
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_nointmain)
save(model_nointmain, file = "model_nointmain.RData")

# Fixed Effects ----------------------------------------------------------------

model_nointfe <- feols(armscontrolsupport ~ mprival
                       + democracy + log(gdppc) + log(tradeopenness)
                       + govideology + intrastateconflict
                       + topic + log(salience + 1)
                       + category + globallyrelevant | country + year,
                       cluster = c("country", "year", "repeatedres"),
                       data = data)
summary(model_nointfe)
save(model_nointfe, file = "model_nointfe.RData")

####### Interaction Effect #####################################################

# No Controls ------------------------------------------------------------------

model_biv <- lm(armscontrolsupport ~ mprival * mpstatus, data = data)
summary(model_biv)
save(model_biv, file = "model_biv.RData")

# Full Model -------------------------------------------------------------------

model_main <- lmer(armscontrolsupport ~ mprival * mpstatus
                   + democracy + log(gdppc) + log(tradeopenness)
                   + govideology + intrastateconflict
                   + region + eu + nato + nuclearpower + armsproducer
                   + topic + log(salience + 1) + category + globallyrelevant
                   + (1 | country) + (1 | year) + (1 | repeatedres),
                   data = data)
summary(model_main)
save(model_main, file = "model_main.RData")

######## Robustness Checks #####################################################

# No Resolution-Level Controls -------------------------------------------------

model_norescont <- lmer(armscontrolsupport ~ mprival * mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_norescont)
save(model_norescont, file = "model_norescont.RData")

# Additional Controls ----------------------------------------------------------

model_addcont <- lmer(armscontrolsupport ~ mprival * mpstatus
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + nomprival + mpally
                      + topic + log(salience + 1) + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data)
summary(model_addcont)
save(model_addcont, file = "model_addcont.RData")

# Ordinal IV -------------------------------------------------------------------

model_ordinaliv <- lmer(armscontrolsupport ~ as.character(mphostlev) * mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_ordinaliv)
save(model_ordinaliv, file = "model_ordinaliv.RData")

# Count IV ---------------------------------------------------------------------

model_countiv <- lmer(armscontrolsupport ~ log(mprivalcount+1) * mpstatus
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1) + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data)
summary(model_countiv)
save(model_countiv, file = "model_countiv.RData")

# Ordinal DV -------------------------------------------------------------------

data$armscontrolsupportordinal <- as.ordered(data$armscontrolsupport)

model_ordinaldv <- clmm(armscontrolsupportordinal ~ mprival * mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_ordinaldv)
save(model_ordinaldv, file = "model_ordinaldv.RData")

# Binary DV --------------------------------------------------------------------

data$armscontrolsupportbinary <- ifelse(data$armscontrolsupport==0
                                        | data$armscontrolsupport==0.5,0,1)

model_binarydv <- glmer(armscontrolsupportbinary ~ mprival * mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data, family = binomial(link = "logit"),
                        control = glmerControl(optimizer = "bobyqa",
                                               optCtrl = list(maxfun = 100000)))
summary(model_binarydv)
save(model_binarydv, file = "model_binarydv.RData")

# CY Level ---------------------------------------------------------------------

datacy <- data %>% group_by(country, year) %>%
  summarize(armscontrolsupport = mean(armscontrolsupport),
            mprival = mean(mprival), democracy = mean(democracy),
            gdppc = mean(gdppc), tradeopenness = mean(tradeopenness),
            govideology = paste(unique(govideology)), mpstatus = mean(mpstatus),
            intrastateconflict = mean(intrastateconflict),
            region = paste(unique(region)), nuclearpower = mean(nuclearpower),
            armsproducer = mean(armsproducer), eu = mean(eu), nato = mean(nato))

model_countryyear <- lmer(armscontrolsupport ~ mprival * mpstatus
                          + democracy + log(gdppc) + log(tradeopenness)
                          + govideology + intrastateconflict
                          + region + eu + nato + nuclearpower + armsproducer
                          + (1 | country) + (1 | year), data = datacy)
summary(model_countryyear)
save(model_countryyear, file = "model_countryyear.RData")

# Lagged IVs -------------------------------------------------------------------

model_lagged <- lmer(armscontrolsupport ~ mprivallag * mpstatus
                     + democracylag + log(gdppclag) + log(tradeopennesslag)
                     + govideologylag + intrastateconflictlag
                     + region + eulag + natolag
                     + nuclearpowerlag + armsproducer
                     + topic + log(salience + 1) + category + globallyrelevant
                     + (1 | country) + (1 | year) + (1 | repeatedres),
                     data = data)
summary(model_lagged)
save(model_lagged, file = "model_lagged.RData")

# Category 1 -------------------------------------------------------------------

model_cat1 <- lmer(armscontrolsupport ~ mprival * mpstatus
                   + democracy + log(gdppc) + log(tradeopenness)
                   + govideology + intrastateconflict
                   + region + eu + nato + nuclearpower + armsproducer
                   + topic + log(salience + 1) + globallyrelevant
                   + (1 | country) + (1 | year) + (1 | repeatedres),
                   data = data[data$category == "1", ])
summary(model_cat1)
save(model_cat1, file = "model_cat1.RData")

# Category 1+2 -----------------------------------------------------------------

model_cat12 <- lmer(armscontrolsupport ~ mprival * mpstatus
                    + democracy + log(gdppc) + log(tradeopenness)
                    + govideology + intrastateconflict
                    + region + eu + nato + nuclearpower + armsproducer
                    + topic + log(salience + 1) + category + globallyrelevant
                    + (1 | country) + (1 | year) + (1 | repeatedres),
                    data = data[data$category == "1" | data$category == "2", ])
summary(model_cat12)
save(model_cat12, file = "model_cat12.RData")

# Category 3+4 -----------------------------------------------------------------

model_cat34 <- lmer(armscontrolsupport ~ mprival * mpstatus
                    + democracy + log(gdppc) + log(tradeopenness)
                    + govideology + intrastateconflict
                    + region + eu + nato + nuclearpower + armsproducer
                    + topic + log(salience + 1) + category + globallyrelevant
                    + (1 | country) + (1 | year) + (1 | repeatedres),
                    data = data[data$category == "3" | data$category == "4", ])
summary(model_cat34)
save(model_cat34, file = "model_cat34.RData")

# Excl. Consensus --------------------------------------------------------------

model_noncons <- lmer(armscontrolsupport ~ mprival * mpstatus
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1) + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$recorded == 1, ])
summary(model_noncons)
save(model_noncons, file = "model_noncons.RData")

# Nuclear Rival ----------------------------------------------------------------

model_nucrival <- lmer(armscontrolsupport ~ nuclearrival * nuclearpower
                       + democracy + log(gdppc) + log(tradeopenness)
                       + govideology + intrastateconflict
                       + region + eu + nato + armsproducer + mpstatus
                       + topic + log(salience + 1)
                       + category + globallyrelevant
                       + (1 | country) + (1 | year) + (1 | repeatedres),
                       data = data)
summary(model_nucrival)
save(model_nucrival, file = "model_nucrival.RData")

# Arms Prod. Rival -------------------------------------------------------------

model_armprrival <- lmer(armscontrolsupport ~ armsprorival * armsproducer
                         + democracy + log(gdppc) + log(tradeopenness)
                         + govideology + intrastateconflict
                         + region + eu + nato + nuclearpower + mpstatus
                         + topic + log(salience + 1)
                         + category + globallyrelevant
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(model_armprrival)
save(model_armprrival, file = "model_armprrival.RData")

# Incl. India+Brazil -----------------------------------------------------------

model_indbrarival <- lmer(armscontrolsupport ~ mprivalindbra * mpstatusindbra
                          + democracy + log(gdppc) + log(tradeopenness)
                          + govideology + intrastateconflict
                          + region + eu + nato + nuclearpower + armsproducer
                          + topic + log(salience + 1)
                          + category + globallyrelevant
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data)
summary(model_indbrarival)
save(model_indbrarival, file = "model_indbrarival.RData")

# CINC 95th Perc. --------------------------------------------------------------

model_cinc95rival <- lmer(armscontrolsupport ~ cinc95rival * cinc95
                          + democracy + log(gdppc) + log(tradeopenness)
                          + govideology + intrastateconflict
                          + region + eu + nato + nuclearpower + armsproducer
                          + topic + log(salience + 1)
                          + category + globallyrelevant
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data)
summary(model_cinc95rival)
save(model_cinc95rival, file = "model_cinc95rival.RData")

# GDP 95th Perc. ---------------------------------------------------------------

model_gdp95rival <- lmer(armscontrolsupport ~ gdp95rival * gdp95
                         + democracy + log(gdppc) + log(tradeopenness)
                         + govideology + intrastateconflict
                         + region + eu + nato + nuclearpower + armsproducer
                         + topic + log(salience + 1)
                         + category + globallyrelevant
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(model_gdp95rival)
save(model_gdp95rival, file = "model_gdp95rival.RData")

# Mil.Ex. 95th Perc. -----------------------------------------------------------

model_milx95rival <- lmer(armscontrolsupport ~ milx95rival * milx95
                          + democracy + log(gdppc) + log(tradeopenness)
                          + govideology + intrastateconflict
                          + region + eu + nato + nuclearpower + armsproducer
                          + topic + log(salience + 1)
                          + category + globallyrelevant
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data)
summary(model_milx95rival)
save(model_milx95rival, file = "model_milx95rival.RData")

# Diplo. 95th Perc. ------------------------------------------------------------

model_dip95rival <- lmer(armscontrolsupport ~ dip95rival * dip95
                         + democracy + log(gdppc) + log(tradeopenness)
                         + govideology + intrastateconflict
                         + region + eu + nato + nuclearpower + armsproducer
                         + topic + log(salience + 1)
                         + category + globallyrelevant
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(model_dip95rival)
save(model_dip95rival, file = "model_dip95rival.RData")

######## Exploratory Analyses ##################################################

# Diplo. 90th Perc. ------------------------------------------------------------

model_dip90rival <- lmer(armscontrolsupport ~ dip90rival * dip90
                         + democracy + log(gdppc) + log(tradeopenness)
                         + govideology + intrastateconflict
                         + region + eu + nato + nuclearpower + armsproducer
                         + topic + log(salience + 1)
                         + category + globallyrelevant
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(model_dip90rival)
save(model_dip90rival, file = "model_dip90rival.RData")

# Diplo. 75th Perc. ------------------------------------------------------------

model_dip75rival <- lmer(armscontrolsupport ~ dip75rival * dip75
                         + democracy + log(gdppc) + log(tradeopenness)
                         + govideology + intrastateconflict
                         + region + eu + nato + nuclearpower + armsproducer
                         + topic + log(salience + 1)
                         + category + globallyrelevant
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(model_dip75rival)
save(model_dip75rival, file = "model_dip75rival.RData")

# All Higher Status ------------------------------------------------------------

model_allhigher <- lmer(armscontrolsupport ~ rival_hi + mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower
                        + armsproducer
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_allhigher)
save(model_allhigher, file = "model_allhigher.RData")

# Non-MP Rival -----------------------------------------------------------------

model_nomprival <- lmer(armscontrolsupport ~ nomprival * mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_nomprival)
save(model_nomprival, file = "model_nomprival.RData")

# MP Author Rival --------------------------------------------------------------

model_mpauthorrival <- lmer(armscontrolsupport ~ mpauthorrival * mpstatus
                            + democracy + log(gdppc) + log(tradeopenness)
                            + govideology + intrastateconflict
                            + region + eu + nato + nuclearpower + armsproducer
                            + topic + log(salience + 1)
                            + category + globallyrelevant
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data)
summary(model_mpauthorrival)
save(model_mpauthorrival, file = "mpauthorrival.RData")

# US Rival ---------------------------------------------------------------------

model_usrival <- lmer(armscontrolsupport ~ usrival
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1)
                      + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$mpstatus == 0, ])
summary(model_usrival)
save(model_usrival, file = "model_usrival.RData")

# Other MP Rival ---------------------------------------------------------------

model_nousrival <- lmer(armscontrolsupport ~ mprivalnous * mpstatus
                        + democracy + log(gdppc) + log(tradeopenness)
                        + govideology + intrastateconflict
                        + region + eu + nato + nuclearpower + armsproducer
                        + topic + log(salience + 1)
                        + category + globallyrelevant
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data)
summary(model_nousrival)
save(model_nousrival, file = "model_nousrival.RData")

# China Rival ------------------------------------------------------------------

model_cirival <- lmer(armscontrolsupport ~ cirival
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1)
                      + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$mpstatus == 0, ])
summary(model_cirival)
save(model_cirival, file = "model_cirival.RData")

# UK Rival ---------------------------------------------------------------------

model_ukrival <- lmer(armscontrolsupport ~ ukrival
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1)
                      + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$mpstatus == 0, ])
summary(model_ukrival)
save(model_ukrival, file = "model_ukrival.RData")

# Russia Rival -----------------------------------------------------------------

model_rurival <- lmer(armscontrolsupport ~ rurival
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1)
                      + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$mpstatus == 0, ])
summary(model_rurival)
save(model_rurival, file = "model_rurival.RData")

# Japan Rival ------------------------------------------------------------------

model_jprival <- lmer(armscontrolsupport ~ jprival
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1)
                      + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$mpstatus == 0, ])
summary(model_jprival)
save(model_jprival, file = "model_jprival.RData")

# France Rival -----------------------------------------------------------------

model_frrival <- lmer(armscontrolsupport ~ frrival
                      + democracy + log(gdppc) + log(tradeopenness)
                      + govideology + intrastateconflict
                      + region + eu + nato + nuclearpower + armsproducer
                      + topic + log(salience + 1)
                      + category + globallyrelevant
                      + (1 | country) + (1 | year) + (1 | repeatedres),
                      data = data[data$mpstatus == 0, ])
summary(model_frrival)
save(model_frrival, file = "model_frrival.RData")

# WMD --------------------------------------------------------------------------

model_wmd <- lmer(armscontrolsupport ~ mprival * mpstatus
                  + democracy + log(gdppc) + log(tradeopenness)
                  + govideology + intrastateconflict
                  + region + eu + nato + nuclearpower + armsproducer
                  + topic + log(salience + 1)
                  + category + globallyrelevant
                  + (1 | country) + (1 | year) + (1 | repeatedres),
                  data = data[data$topic == "Nuclear Weapons"
                              | data$topic
                              == "Chemical and Biological Weapons", ])
summary(model_wmd)
save(model_wmd, file = "model_wmd.RData")

# Conventional Weapons ---------------------------------------------------------

model_conventional <- lmer(armscontrolsupport ~ mprival * mpstatus
                           + democracy + log(gdppc) + log(tradeopenness)
                           + govideology + intrastateconflict
                           + region + eu + nato + nuclearpower + armsproducer
                           + log(salience + 1) + category + globallyrelevant
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data = data[data$topic == "Conventional Weapons", ])
summary(model_conventional)
save(model_conventional, file = "model_conventional.RData")

# Others -----------------------------------------------------------------------

model_others <- lmer(armscontrolsupport ~ mprival * mpstatus
                     + democracy + log(gdppc) + log(tradeopenness)
                     + govideology + intrastateconflict
                     + region + eu + nato + nuclearpower + armsproducer
                     + log(salience + 1) + category + globallyrelevant
                     + (1 | country) + (1 | year) + (1 | repeatedres),
                     data = data[data$topic == "Others", ])
summary(model_others)
save(model_others, file = "model_others.RData")

# Disarmament ------------------------------------------------------------------

model_disarm <- lmer(armscontrolsupport ~ mprival * mpstatus
                     + democracy + log(gdppc) + log(tradeopenness)
                     + govideology + intrastateconflict
                     + region + eu + nato + nuclearpower + armsproducer
                     + topic + log(salience + 1)
                     + category + globallyrelevant
                     + (1 | country) + (1 | year) + (1 | repeatedres),
                     data = data[data$disarm > mean(data$disarm), ])
summary(model_disarm)
save(model_disarm, file = "model_disarm.RData")

# Non-Proliferation ------------------------------------------------------------

model_prolif <- lmer(armscontrolsupport ~ mprival * mpstatus
                     + democracy + log(gdppc) + log(tradeopenness)
                     + govideology + intrastateconflict
                     + region + eu + nato + nuclearpower + armsproducer
                     + topic + log(salience + 1)
                     + category + globallyrelevant
                     + (1 | country) + (1 | year) + (1 | repeatedres),
                     data = data[data$prolif > mean(data$prolif), ])
summary(model_prolif)
save(model_prolif, file = "model_prolif.RData")
